<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="test">
    <button @click="destoryVM">destory vm</button>
    <p v-show="isShow">尚硅谷IT教育</p>
</div>

<script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript">
    new Vue({
        el: "#test",
        data: {
            isShow: true
        },
        //1.初始化阶段
        beforeCreate(){
            console.log("beforeCreate()");
        },
        created(){
            console.log("created()")
        },
        beforeMount(){
            console.log("beforeMount()")
        },
        mounted(){//初始化显示之后立即调用(1次)
           this.interValId = setInterval(() => {
                console.log("---")
                this.isShow = !this.isShow;
            },1000)
        },
        //2.更新阶段
        beforeUpdate(){
            console.log("beforeUpdate()");
        },
        updated(){
            console.log("updated()");
        },

        //3.死亡阶段
        beforeDestroy(){//死亡之前调用(1次)
            console.log("beforeDestroy()");
            //清楚定时器
            clearInterval(this.interValId);
        },
        destroyed() {
            console.log("destroyed()")
        },

        methods: {
            destoryVM(){
                //干掉VM
                this.$destroy();
            }
        }
    });


</script>
</body>
</html>